﻿using ZilLion.Service.Core.DapperWrapper;
using ZilLion.Service.Core.DapperWrapper.SqlServer;
using ZilLion.Service.ZilLionOss.Domain.Entitys;
using ZilLion.Service.ZilLionOss.Domain.Repositorys.Interface;

namespace ZilLion.Service.ZilLionOss.Domain.Repositorys
{
    public class OssUserRoleRepository : SqlServerRespository<OssUserRoleEntity>, IOssUserRoleRepository
    {
        public OssUserRoleRepository()
        {
            Context = new OssContext();
        }

        public void AddOssUserRoles(OssUserRoleEntity entity, UnitOfWork unit = null)
        {
            Add(entity, unit);
        }


        public void DeleteRoleByUserid(long userid, UnitOfWork unitOfWork = null)
        {
            var entitys = GetList(
                "SELECT userid as UserId,roleid as RoleId FROM oss_user_roles WHERE UserId=@userid ",
                new {userid});

            foreach (var entity in entitys)
                Remove(entity, unitOfWork);
        }
    }
}